package com.ruoyi.robot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.robot.domain.InterfaceSetting;
import com.ruoyi.robot.service.IInterfaceSettingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接口配置Controller
 * 
 * @author ruoyi
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/robot/interface")
public class InterfaceSettingController extends BaseController
{
    @Autowired
    private IInterfaceSettingService interfaceSettingService;

    /**
     * 查询接口配置列表
     */
    @PreAuthorize("@ss.hasPermi('robot:interface:list')")
    @GetMapping("/list")
    public TableDataInfo list(InterfaceSetting interfaceSetting)
    {
        startPage();
        List<InterfaceSetting> list = interfaceSettingService.selectInterfaceSettingList(interfaceSetting);
        return getDataTable(list);
    }

    /**
     * 导出接口配置列表
     */
    @PreAuthorize("@ss.hasPermi('robot:interface:export')")
    @Log(title = "接口配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InterfaceSetting interfaceSetting)
    {
        List<InterfaceSetting> list = interfaceSettingService.selectInterfaceSettingList(interfaceSetting);
        ExcelUtil<InterfaceSetting> util = new ExcelUtil<InterfaceSetting>(InterfaceSetting.class);
        util.exportExcel(response, list, "接口配置数据");
    }

    /**
     * 获取接口配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('robot:interface:query')")
    @GetMapping(value = "/{interfaceName}")
    public AjaxResult getInfo(@PathVariable("interfaceName") String interfaceName)
    {
        return success(interfaceSettingService.selectInterfaceSettingByInterfaceName(interfaceName));
    }

    /**
     * 新增接口配置
     */
    @PreAuthorize("@ss.hasPermi('robot:interface:add')")
    @Log(title = "接口配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InterfaceSetting interfaceSetting)
    {
        return toAjax(interfaceSettingService.insertInterfaceSetting(interfaceSetting));
    }

    /**
     * 修改接口配置
     */
    @PreAuthorize("@ss.hasPermi('robot:interface:edit')")
    @Log(title = "接口配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InterfaceSetting interfaceSetting)
    {
        return toAjax(interfaceSettingService.updateInterfaceSetting(interfaceSetting));
    }

    /**
     * 删除接口配置
     */
    @PreAuthorize("@ss.hasPermi('robot:interface:remove')")
    @Log(title = "接口配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{interfaceNames}")
    public AjaxResult remove(@PathVariable String[] interfaceNames)
    {
        return toAjax(interfaceSettingService.deleteInterfaceSettingByInterfaceNames(interfaceNames));
    }
}
